import {defineStore} from "pinia";
import {ref} from "vue";
import {jsx} from "vue/jsx-runtime";


export const useTaskStore = defineStore("task", () => {
    const lineInfo = ref({
        lineList: [],
        updateStatus: true,
    })

    const cardInfo = ref({})
    function setCardInfo(info) {
        cardInfo.value = info;
        localStorage.removeItem("cardInfo")
        localStorage.setItem("cardInfo", JSON.stringify(info));
    }
    function getCardInfo() {
        return JSON.parse(localStorage.getItem("cardInfo")) || {};
    }

    // 更新列表时触发
    function updateLineInfo(list) {
        lineInfo.value.lineList = list
        lineInfo.value.updateStatus = false
        localStorage.setItem("lineList",JSON.stringify(lineInfo.value.lineList))
        localStorage.setItem("lineUpdateStatus",lineInfo.value.updateStatus)
    }
    // 清空缓存
    function removeLineInfo() {
        lineInfo.value.lineList = []
        lineInfo.value.updateStatus = true
        localStorage.setItem("lineList",JSON.stringify(lineInfo.value.lineList))
        localStorage.setItem("lineUpdateStatus",JSON.stringify(lineInfo.value.updateStatus))
    }
    // 获取列表更新状态
    function getLineStatus() {
        return JSON.parse(localStorage.getItem("lineUpdateStatus"));
    }
    // 获取列表
    function getLineList() {
        return JSON.parse(localStorage.getItem("lineList")) || [];
    }
    return {
        lineInfo,
        updateLineInfo,
        removeLineInfo,
        getLineStatus,
        getLineList
    }

})
